﻿// ***********************************************************************
// Apache 2.0 License
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY 
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR 
// PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.
// ***********************************************************************
// Assembly  : ContractMeow.Api.Dtos
// File      : ReferenceKey.cs
//
// ***********************************************************************

using System;

namespace ContractMeow.Api.Dtos
{
	/// <summary>
	/// Struct ReferenceKey
	/// </summary>
	public struct ReferenceKey : IEquatable<ReferenceKey>
	{
		/// <summary>
		/// The _type
		/// </summary>
		private readonly String _type;
		/// <summary>
		/// The _id
		/// </summary>
		private readonly Int64 _id;
		/// <summary>
		/// The _hash code
		/// </summary>
		private readonly Int32 _hashCode;

		/// <summary>
		/// Threads the specified id.
		/// </summary>
		/// <param name="id">The id.</param>
		/// <returns>ReferenceKey.</returns>
		public static ReferenceKey Thread(Int64 id)
		{
			return new ReferenceKey("thread", id);
		}

		/// <summary>
		/// Messages the specified id.
		/// </summary>
		/// <param name="id">The id.</param>
		/// <returns>ReferenceKey.</returns>
		public static ReferenceKey Message(Int64 id)
		{
			return new ReferenceKey("message", id);
		}

		/// <summary>
		/// Groups the specified id.
		/// </summary>
		/// <param name="id">The id.</param>
		/// <returns>ReferenceKey.</returns>
		public static ReferenceKey Group(Int64 id)
		{
			return new ReferenceKey("group", id);
		}

		/// <summary>
		/// Users the specified id.
		/// </summary>
		/// <param name="id">The id.</param>
		/// <returns>ReferenceKey.</returns>
		public static ReferenceKey User(Int64 id)
		{
			return new ReferenceKey("user", id);
		}

		/// <summary>
		/// Gets the type.
		/// </summary>
		/// <value>The type.</value>
		public String Type
		{
			get { return _type; }
		}

		/// <summary>
		/// Gets the id.
		/// </summary>
		/// <value>The id.</value>
		public Int64 Id
		{
			get { return _id; }
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="ReferenceKey" /> struct.
		/// </summary>
		/// <param name="type">The type.</param>
		/// <param name="id">The id.</param>
		public ReferenceKey(String type, Int64 id)
		{
			this._type = type;
			this._id = id;
			this._hashCode = (id.GetHashCode() * 397) ^ type.GetHashCode();
		}

		/// <summary>
		/// Equalses the specified other.
		/// </summary>
		/// <param name="other">The other.</param>
		/// <returns>Boolean.</returns>
		public Boolean Equals(ReferenceKey other)
		{
			return Equals(other._id, _id) && Equals(other._type, _type);
		}

		/// <summary>
		/// Indicates whether this instance and a specified object are equal.
		/// </summary>
		/// <param name="obj">Another object to compare to.</param>
		/// <returns>true if <paramref name="obj" /> and this instance are the same type and represent the same value; otherwise, false.</returns>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2231:OverloadOperatorEqualsOnOverridingValueTypeEquals")]
		public override Boolean Equals(Object obj)
		{
			return !ReferenceEquals(null, obj) && obj is ReferenceKey && Equals((ReferenceKey)obj);
		}

		/// <summary>
		/// Returns the hash code for this instance.
		/// </summary>
		/// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
		public override Int32 GetHashCode()
		{
			unchecked
			{
				return _hashCode;
			}
		}
	}
}